package com.hydra.auth.config.points;

import com.hydra.base.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Jwt验证实体
 * @Author Hydra
 * @Date 2022/4/18 13:18
 */
@Slf4j
public class OAuth2AuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response,
                         AuthenticationException exception) throws IOException {
        log.warn("登录信息异常："+exception.getMessage(), exception);
//        response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), authException.getMessage());

        ResponseUtil.writeError(request, response, HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage());
    }

}